package com.example.demo.warn.manager;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 预警线程池管理
 *
 * @author yuanz
 * @date 2024/06/06
 */
public class WarnThreadManager {
    private static int corePoolSize = Runtime.getRuntime().availableProcessors();

    private static ThreadFactory namedFactory = new ThreadFactoryBuilder().setNameFormat("warn-%d").build();
    /**
     * corePoolSize用于指定核心线程数量
     * maximumPoolSize指定最大线程数
     * keepAliveTime和TimeUnit指定线程空闲后的最大存活时间
     */
    public static ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, corePoolSize + 1, 10L, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(1000), namedFactory, new ThreadPoolExecutor.AbortPolicy());

}
